<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
	array('op'=>'list','title'=>'口碑意向量'),
	array('op'=>'edit','title'=>'添加口碑量'),
);
$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['workers']=$this->getall('worker',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
//客户列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('koubei_storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid'],'from_type'=>array(3,4),'baom_time'=>0);
	if(isset($_RQ['status']) && $_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	$list=pdo_getslice('jy_yxw_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['id']);
			if($item['from_type']==3){
				$item['from_title']=pdo_getcolumn('jy_yxw_xuesheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['from_xueshengid']),'title');
			}
			if($item['from_type']==4){
				$item['from_title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['from_workerid']),'title');
			}
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['worker6id']),'title');
			$item['worker6title']=$item['worker6title']?:'无';
			if($item['from_type']==4 && $item['from_workerid'] && !$item['workerheid']){
				pdo_update('jy_yxw_member',array('workerheid'=>$item['from_workerid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
				pdo_update('jy_yxw_infee_log',array('workerheid'=>$item['from_workerid']),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['id']));
			}
			if($item['workerheid']){
				$workerhe=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['workerheid']),array('role','title'));
				$item['workerhetitle']=$this->user_role[$workerhe['role']].':'.$workerhe['title'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_message'=>'确认删除该客户吗？','total'=>$total,'psize'=>$psize,'edit'=>true,'del_op'=>'del','html_to'=>'list_html','list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			//array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'jibie_type','title'=>'客户级别','type'=>'radio2','options'=>'jibie_type'),
			array('name'=>'from_type','title'=>'渠道','type'=>'radio2','options'=>'from_type'),
			array('type'=>'string','title'=>'口碑员工/售后','name'=>'from_title','help'=>''),
			array('name'=>'worker5id','title'=>'电客员','type'=>'select2','options'=>'workers'),
			array('type'=>'img_string','title'=>'成交跟进',
            'data'=>array(
                array('title'=>'跟进师:','name'=>'worker6title'),
                array('title'=>'','name'=>'workerhetitle'),
                )
            ),
			array('name'=>'worker7id','title'=>'体验员','type'=>'select2','options'=>'workers'),
			array('name'=>'worker8id','title'=>'试用员','type'=>'select2','options'=>'workers'),
			array('name'=>'status','title'=>'状态','type'=>'radio2','options'=>'status'),
			array('name'=>'createtime','title'=>'添加日期','type'=>'time'),
			array('type'=>'href','action'=>'/member.genjin_log/onelist/','title'=>'查看跟进记录'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_yxw/xiaoshou.setgenjin_log/set10/','title'=>'处理跟进','show'=>array('status'=>array(-1,0,2,4,6,8,32,33,34))),
			array('type'=>'href','action'=>'jy_yxw/jiaoxue.koubei/setworker6id2/','title'=>'设置跟进员工','show'=>array('worker6id'=>0)),
			array('type'=>'href','action'=>'jy_yxw/jiaoxue.koubei/setworker6id/','title'=>'分给销售员','show'=>array('worker6id'=>0)),
			array('type'=>'modal','action'=>'jy_yxw/jiaoxue.koubei/jiaofee2','title'=>'交定金','show'=>array('status'=>array(4,32,6,8))),
			array('type'=>'modal','action'=>'jy_yxw/jiaoxue.koubei/jiaofee2','title'=>'重新交定金','show'=>array('status'=>array(39))),
			array('type'=>'href','action'=>'jy_yxw/jiaoxue.koubei/jiaofee1','title'=>'成交提交','show'=>array('status'=>array(4,32,6,8,9))),
			array('type'=>'href','action'=>'jy_yxw/jiaoxue.koubei/jiaofee1','title'=>'重新成交提交','show'=>array('status'=>array(38))),
			array('type'=>'modal','action'=>'jy_yxw/jiaoxue.koubei/workerheid','title'=>'设置合作人'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'客户名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status2'),
		),
	);
	$return['status']=$this->member_status;
	$return['status2']=array('all'=>'全部',0=>'初入客户',2=>'跟进中',9=>'已交定金');
	$return['jibie_type']=$this->member_jibie_type;
	$return['from_type']=$this->member_from_type;
	$return['from1_type']=$this->member_from1_type;
	$return['from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$postdata['koubei_storeid']=$_SESSION['storeid'];
		$this->model('member')->add($postdata);
		exi('添加成功','','/jiaoxue.koubei/');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		$item=array();
	}
	$item['from_type']=3;
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'tabs'=>$tabs,
		'edit'=>$this->model('member')->edit_item(true),
	);
	$return['sex']=$this->sex;
	$return['xueli_type']=$this->xueli_type;
	$return['from_type']=array(3=>'售后口碑',4=>'员工口碑',);
	$return['member_from1_type']=$this->member_from1_type;
	$return['member_from2_type']=$this->member_from2_type;
	$return['workers']=$this->getall('worker',array('status'=>1,'role'=>array(9,10,11),'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='setworker6id'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array();
		if(!$post['storeid'] || !$post['worker6id']){
			exi('请先门店和销售员！','error');
		}
		$update['storeid']=$post['storeid'];
		$update['worker6id']=$post['worker6id'];
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','//list/status=all');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'分给销售员',
	);
	$htmls['edit']=array(
		array('type'=>'select2','title'=>'招生门店','name'=>'storeid','options'=>'stores','title2'=>'分配销售员','name2'=>'worker6id','options2'=>'workers'),
	);
	$return['stores']=$this->getall('store',array('type'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	foreach($return['stores'] as &$sv){
		$sv['workers']=$this->getall('worker',array('status'=>1,'role'=>6,'storeid'=>$sv['id'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='setworker6id2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array();
		if(!$post['worker6id']){
			exi('请先本门店员工！','error');
		}
		$update['worker6id']=$post['worker6id'];
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','//list/status=all');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'分给门店员工',
	);
	$htmls['edit']=array(
		array('type'=>'select','title'=>'分配门店员工','name'=>'worker6id','options'=>'workers'),
	);
	$return['workers']=$this->getall('worker',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
//成交提交
if($_RQ['op']=='jiaofee1'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['tofee']){
			exi('请填写成交费用！','error');
		}
		if($post['bufee']>0 && (!$post['bankno'] || !$post['banktitle'] || !$post['bankimg'])){
			exi('填写补贴费用，银行信息必填！','error');
		}
		if(!$post['cardno'] || !$post['cardimg1'] || !$post['cardimg2'] || !$post['xueli'] || !$post['xueliimg']){
			exi('请完善客户成交信息！','error');
		}
		if(!$post['danganimage1'] || !$post['danganimage2'] || !$post['px_file'] || !$post['rx_file'] || !$post['jj_file']){
			exi('请完善客户档案信息！','error');
		}
		if(($post['pay_type']==1 || $post['pay_type']==2 || $post['pay_type']==3) && !$post['fen_file']){
			exi('请上传《分期承诺书》！','error');
		}
		$id=$post['id'];
		if($post['memberid'] && $id){
			$memberid=$post['memberid'];
		}else{
			$memberid=$id;
		}
		$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid),array('koubei_storeid','worker5id','worker6id','from_type','from1_type','from2_type'));
		$data=array(
				'tofee'=>$post['tofee'],
				'classid'=>$post['classid'],
				'toremark'=>trim($post['toremark']),
				'workerid'=>intval($_SESSION['workerid']),
				'worker5id'=>$member['worker5id'],
				'worker6id'=>$member['worker6id'],
				'from_type'=>$member['from_type'],
				'from1_type'=>$member['from1_type'],
				'from2_type'=>$member['from2_type'],
				'koubei_storeid'=>$member['koubei_storeid'],
				'pay_type'=>intval($post['pay_type']),
				'daipay_type'=>intval($post['daipay_type']),
				'dai_time'=>intval($post['dai_time']),
				'jiaobenfee'=>trim($post['jiaobenfee']),
				'bufee'=>trim($post['bufee']),
				'fen_file'=>ijson_encode($post['fen_file']),
				'fen_log'=>ijson_encode($post['fen_log']),
				'bao_time'=>strtotime($post['bao_time']),
				'status'=>0,
		);
		if($post['memberid'] && $id){
			$memberid=$post['memberid'];
			if(!$post['storeid']){
				$data['storeid']=$_SESSION['storeid'];
			}
			$this->update('infee_log',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['storeid']=$_SESSION['storeid'];
			$data['memberid']=$id;
			$data['type']=1;
			$data['createtime']=time();
			$this->insert('infee_log',$data);
			$memberid=$id;
		}
		$update=array(
			'toclassid'=>$post['classid'],
			'bao_time'=>strtotime($post['bao_time']),
			'status'=>37,
			'cardno'=>$post['cardno'],
			'cardimg1'=>$post['cardimg1'],
			'cardimg2'=>$post['cardimg2'],
			'xueli'=>$post['xueli'],
			'xueliimg'=>$post['xueliimg'],
			'bankno'=>$post['bankno'],
			'banktitle'=>$post['banktitle'],
			'bankimg'=>$post['bankimg'],
		);
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']?:$id));
		$dangan=array(
			'pay_type'=>intval($post['pay_type']),
			'fen_file'=>ijson_encode($post['fen_file']),
			'danganimage1'=>ijson_encode($post['danganimage1']),
			'danganimage2'=>ijson_encode($post['danganimage2']),
			'px_file'=>ijson_encode($post['px_file']),
			'rx_file'=>ijson_encode($post['rx_file']),
			'jj_file'=>ijson_encode($post['jj_file']),
		);
		$this->model('uplog')->updangan($dangan,$memberid);
		exi('操作成功！','','/jiaoxue.koubei/');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['memberid']=0;
		if($item['status']==38){
			$infee_log=pdo_get('jy_yxw_infee_log',array('type'=>1,'status'=>2,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['id']),'','id desc');
		}
		if($infee_log['id']){
			$dangan=pdo_get('jy_yxw_dangan',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['id']));
			$infee_log['fen_log']=json_decode($infee_log['fen_log'],true);
			$infee_log['title']=$item['title'];
			$infee_log['xueliimg']=$item['xueliimg'];
			$infee_log['xueli']=$item['xueli'];
			$infee_log['cardno']=$item['cardno'];
			$infee_log['cardimg1']=$item['cardimg1'];
			$infee_log['cardimg2']=$item['cardimg2'];
			$infee_log['bankno']=$item['bankno'];
			$infee_log['banktitle']=$item['banktitle'];
			$infee_log['bankimg']=$item['bankimg'];
			$infee_log['fen_file']=json_decode($dangan['fen_file'],true);
			$infee_log['danganimage1']=json_decode($dangan['danganimage1'],true);
			$infee_log['danganimage2']=json_decode($dangan['danganimage2'],true);
			$infee_log['px_file']=json_decode($dangan['px_file'],true);
			$infee_log['rx_file']=json_decode($dangan['rx_file'],true);
			$infee_log['jj_file']=json_decode($dangan['jj_file'],true);
			$infee_log['istip']=1;
			$item=$infee_log;
		}
	}else{
		exi('请先选择客户','error');
	}
	$basic=$this->plugin_setting('basic');
	$item['jiaobenfee']=$basic['jiaobenfee'.$item['xueli']];
	$item['bao_time']=$item['bao_time']?date('Y-m-d H:i:s',$item['bao_time']):date('Y-m-d H:i:s');
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'售后成交',
	);
	$htmls['edit']=array(
		array('type'=>'tip','title'=>'审核不通过的原因：'.$item['remark'],'show'=>array('istip'=>1)),
		array('type'=>'copy','title'=>'售后姓名','name'=>'title'),
		//array('type'=>'select','title'=>'成交售后群','name'=>'classid','options'=>'class'),
		array('type'=>'copy','title'=>'售后成本','name'=>'jiaobenfee'),
		array('type'=>'unitstring','unit'=>'元','title'=>'成交费','name'=>'tofee','must'=>true),
		array('type'=>'unitstring','unit'=>'元','title'=>'补贴费用','name'=>'bufee'),
		array('type'=>'time','unit'=>'元','title'=>'成交时间','name'=>'bao_time'),
		array('type'=>'radio','options'=>'pay_types','title'=>'支付方式','name'=>'pay_type'),
		array('type'=>'radio','options'=>'daipay_types','title'=>'贷款方式','name'=>'daipay_type','show'=>array('pay_type'=>array(2,3))),
		array('type'=>'images','title'=>'现金分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>1)),
		array('type'=>'images','title'=>'贷款分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>array(2,3))),
		array('type'=>'array','title'=>'分期明细','name'=>'fen_log','show'=>array('pay_type'=>1),'add_tip'=>'添加一个分期',
			'list'=>array(
					array('type'=>'unitstring','unit'=>'元','name'=>'fee','title'=>'当期金额'),
					array('type'=>'string','name'=>'time','title'=>'当期时间'),
			),
			'details'=>array(
					array('type'=>'unitstring','unit'=>'元','name'=>'fee','title'=>'当期金额'),
					array('type'=>'time','name'=>'time','title'=>'当期时间'),
			)
		),
		array('type'=>'text','title'=>'备注','name'=>'toremark'),
		array('type'=>'help','title'=>'完善客户信息'),
		array('type'=>'image','title'=>'学信网/证书','name'=>'xueliimg','must'=>true),
		array('type'=>'radio','title'=>'学历','name'=>'xueli','options'=>'xueli_type','must'=>true),
		array('type'=>'string','title'=>'身份证号码','name'=>'cardno','must'=>true),
		array('type'=>'image','title'=>'身份证正面','name'=>'cardimg1','must'=>true),
		array('type'=>'image','title'=>'身份证背面','name'=>'cardimg2','must'=>true),
		array('type'=>'string','title'=>'银行卡号','name'=>'bankno','must'=>true),
		array('type'=>'string','title'=>'银行支行','name'=>'banktitle','must'=>true),
		array('type'=>'image','title'=>'银行卡正面照片','name'=>'bankimg','must'=>true),
		array('type'=>'images','title'=>'用户档案照片A面','name'=>'danganimage1','must'=>true),
		array('type'=>'images','title'=>'用户档案照片B面','name'=>'danganimage2','must'=>true),
		array('type'=>'images','title'=>'用户培训协议','name'=>'px_file','must'=>true),
		array('type'=>'images','title'=>'用户入学协议','name'=>'rx_file','must'=>true),
		array('type'=>'images','title'=>'用户交接表','name'=>'jj_file','must'=>true),
	);
	$jiaoxueid=$this->getcolumn('store',array('id'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),'jiaoxueid');
	$return['class']=$this->getall('class',array('status'=>0,'storeid'=>$jiaoxueid,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	$return['xueli_type']=$this->xueli_type;
	$return['htmls']=$htmls;
	exi($return);
}
//定金提交
if($_RQ['op']=='jiaofee2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['memberid'] && $id){
			$memberid=$post['memberid'];
		}else{
			$memberid=$id;
		}	
		$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$memberid),array('koubei_storeid','worker5id','worker6id','from_type','from1_type','from2_type'));
		$data=array(
			'tofee'=>$post['tofee'],
			'classid'=>$post['classid'],
			'toremark'=>trim($post['toremark']),
			'workerid'=>intval($_SESSION['workerid']),
			'worker5id'=>$member['worker5id'],
			'worker6id'=>$member['worker6id'],
			'from_type'=>$member['from_type'],
			'from1_type'=>$member['from1_type'],
			'from2_type'=>$member['from2_type'],
			'koubei_storeid'=>$member['koubei_storeid'],
			'status'=>0,
		);
		if($post['memberid'] && $id){
			if(!$post['storeid']){
				$data['storeid']=$_SESSION['storeid'];
			}
			$this->update('infee_log',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['storeid']=$_SESSION['storeid'];
			$data['memberid']=$id;
			$data['type']=2;
			$data['createtime']=time();
			$this->insert('infee_log',$data);
		}
		pdo_update('jy_yxw_member',array('toclassid'=>$post['classid'],'ding_time'=>time(),'status'=>9),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']?:$id));
		exi('操作成功！','','/jiaoxue.koubei/');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['memberid']=0;
		if($item['status']==39){
			$infee_log=pdo_get('jy_yxw_infee_log',array('type'=>2,'status'=>2,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['id']),'','id desc');
		}
		if($infee_log['id']){
			$infee_log['title']=$item['title'];
			$infee_log['xueli']=$item['xueli'];
			$infee_log['istip']=1;
			$item=$infee_log;
		}
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'售后交定金',
	);
	$htmls['edit']=array(
		array('type'=>'tip','title'=>'审核不通过的原因：'.$item['remark'],'show'=>array('istip'=>1)),
		array('type'=>'copy','title'=>'售后姓名','name'=>'title'),
		//array('type'=>'select','title'=>'成交售后群','name'=>'classid','options'=>'class'),
		array('type'=>'unitstring','unit'=>'元','title'=>'交定金费','name'=>'tofee'),
		array('type'=>'text','title'=>'备注','name'=>'toremark'),
	);
	$jiaoxueid=$this->getcolumn('store',array('id'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),'jiaoxueid');
	$return['class']=$this->getall('class',array('status'=>0,'storeid'=>$jiaoxueid,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='tuibao' || $_RQ['op']=='tuibao2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array('up_time'=>time(),'status'=>101);
		if($_RQ['op']=='tuibao2'){
			$data=array(
				'fee'=>$post['fee'],
				'isfee'=>$post['isfee'],
				'infee'=>$post['isfee'],
				'remark'=>trim($post['remark']),
				'tuiimage'=>trim($post['tuiimage']),
				'status'=>0,
			);
			pdo_update('jy_yxw_tuifee_log',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			$id=$post['memberid'];
		}else{
			$id=$post['id'];
			$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),array('worker5id','worker6id','from_type','from1_type','from2_type'));
			$data=array(
				'memberid'=>$id,
				'fee'=>$post['fee'],
				'isfee'=>$post['isfee'],
				'infee'=>$post['isfee'],
				'from_type'=>$member['from_type'],
				'from1_type'=>$member['from1_type'],
				'from2_type'=>$member['from2_type'],
				'remark'=>trim($post['remark']),
				'tuiimage'=>trim($post['tuiimage']),
				'oldstatus'=>$post['status'],
			);
			$data['uniacid']=$_SESSION['uniacid'];
			$data['storeid']=$_SESSION['storeid'];
			$data['worker6id']=$member['worker6id'];
			$data['worker5id']=$member['worker5id'];
			$data['createtime']=time();
			$this->insert('tuifee_log',$data);
		}
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		pdo_update('jy_yxw_xuesheng',$update,array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$id));
		exi('操作成功！','','/jiaoxue.koubei/');
	}
	if($_RQ['id']){
		if($_RQ['op']=='tuibao2'){
			$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
			$item=pdo_get('jy_yxw_tuifee_log',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$member['id']),'','id desc');
			$item['title']=$member['title'];
		}else{
			$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
			$item['infeeid']=pdo_getcolumn('jy_yxw_infee_log',array('tuifeeid'=>0,'type'=>1,'uniacid'=>$_SESSION['uniacid'],'memberid'=>$_RQ['id']),'id');
			if(!$item['infeeid']){
				exi('没找到该售后的缴费记录！不能申请退费','error');
			}
		}
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>$_RQ['op']=='tuibao2'?'重新发起退成交':'发起退成交',
	);
	$htmls['edit']=array(
		array('type'=>'tip','title'=>'发起“退成交”申请，成交成功后退成交，向“店长”发起，店长确认达到“财务”系统。'),
		array('type'=>'copy','title'=>'售后姓名','name'=>'title'),
		array('type'=>'unitstring','unit'=>'元','title'=>'已交金额','name'=>'fee'),
		array('type'=>'unitstring','unit'=>'元','title'=>'需收取金额','name'=>'isfee','help'=>'退费需扣除的部分（比如已上课7天，需扣除1000），这里填1000'),
		array('type'=>'image','title'=>'退成交协议图片','name'=>'tuiimage'),
		array('type'=>'text','title'=>'退成交原因','name'=>'remark'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='workerheid'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array('workerheid'=>intval($post['workerheid']));
		$uplog=array(
			'memberid'=>$id,
			'remark'=>'设置合作人',
			'status'=>1,
			'type'=>2,
		);
		$this->model('uplog')->addgenjin_log($uplog);
		pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		pdo_update('jy_yxw_infee_log',$update,array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$id));
		pdo_update('jy_yxw_tuifee_log',$update,array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$id));
		exi('操作成功！','','//list/status=all');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择客户','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'设置合作人',
	);
	$htmls['edit']=array(
		array('type'=>'select','title'=>'设置合作人','name'=>'workerheid','options'=>'workers'),
	);
	$jiaoxueid=$this->getcolumn('store',array('id'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),'jiaoxueid');
	$return['workers']=$this->getall('worker',array('status'=>1,'role'=>array(6,9,10,11),'id <>'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']),array('id','title','storeid'),'id','storeid asc');	
	foreach($return['workers'] as &$wv){
		$storetitle=$this->getcolumn('store',array('id'=>$wv['storeid'],'uniacid'=>$_SESSION['uniacid']),'title');
		$wv['title']='['.$storetitle.']'.$wv['title'];
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid'],'from_type'=>array(3,4));
	if($_RQ['jibie_type']!='all'){
		$params['jibie_type']=intval($_RQ['jibie_type']);
	}
	$return['params']['jibie_type']=$_RQ['jibie_type'];
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$list=pdo_getall('jy_yxw_member',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['jibie_type']=$this->member_jibie_type[$item['jibie_type']];
			$item['from_type']=$this->member_from_type[$item['from_type']];
			$item['status']=$this->member_status[$item['status']];
			$item['xueli']=$this->xueli_type[$item['xueli']];
		}
	}
	$header=array(
		'id'=>'客户ID',
		'title'=>'客户名称',
		'mobile'=>'手机号',
		'jibie_type'=>'级别',
		'from_type'=>'渠道',
		'xueli'=>'学历',
		'status'=>'状态',
		'createtime'=>'注册时间',
	);
	model('core/tools')->export2excel($header,$list,'客户数据');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			$this->model('member')->check_del($id,'xuesheng');
			pdo_delete('jy_yxw_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}